package 数据结构和算法入门计划8月开始;
// https://leetcode-cn.com/problems/search-in-a-binary-search-tree/
public class 树700二叉搜索树中的搜索0827 {

     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }

    class Solution {
        public TreeNode searchBST(TreeNode root, int val) {
            if (root == null || val == root.val) return root;

            return val < root.val ? searchBST(root.left, val) : searchBST(root.right, val);
        }
    }

}
